package com.mylove.judas.yaya.ui.activity.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.mylove.judas.yaya.R;
import com.mylove.judas.yaya.mvp.presenter.BaseView;
import com.widget.toolbar.ToolBarX;

/**
 * Created by Judas on 2017/6/10.
 */

public abstract class BaseActivity extends AppCompatActivity{

    protected Context mContext;

    private Toolbar toolbar;
    private LinearLayout ll_content;

    private ToolBarX toolbarX;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);

        mContext = this;

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        ll_content = (LinearLayout) findViewById(R.id.ll_content);

        addContentView(getLayoutId());

        initView();
        setListener();
    }

    /**
     * 获取资源ID
     * @return
     */
    public abstract int getLayoutId();

//    @Override
//    public void setContentView(@LayoutRes int layoutResID) {
////        super.setContentView(layoutResID);
//        setContentView(View.inflate(this, layoutResID, null));
//    }
//
//    @Override
//    public void setContentView(View view) {
//        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//        ll_content.addView(view, params);
//    }

    public void addContentView(@LayoutRes int layoutResID) {
//        super.setContentView(layoutResID);
        addContentView(View.inflate(this, layoutResID, null));
    }

    public void addContentView(View view) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        ll_content.addView(view, params);
    }

    public void initView(){

    }

    public void setListener(){

    }

//    @Override
//    public View findViewById(@IdRes int id) {
//
//        if(ll_content == null){
//            return findViewById(id);
//        }
//
//        return ll_content.findViewById(id);
//    }

    /**
     * 获取ToolBarX
     * @return
     */
    public ToolBarX getToolbarX() {
        if(toolbarX == null){
            toolbarX = new ToolBarX(this, toolbar);
        }
        return toolbarX;
    }


    public void showToast(String msg){
        Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
    }

    public void showToast(int resId){
        Toast.makeText(mContext, resId, Toast.LENGTH_SHORT).show();
    }

}
